package com.hunttown.mes.convert;

import com.google.common.collect.Lists;
import com.hunttown.mes.common.utils.BeanUtils;
import com.hunttown.mes.domain.MesProduceWorkmanshipProcess;
import com.hunttown.mes.rpc.exception.ConvertException;
import com.hunttown.mes.rpc.domain.MesProduceWorkmanshipProcessDTO;
import com.hunttown.mes.rpc.domain.enums.ErrorCode;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.List;

/**
 * created by wangjunfu on 2022-03-30 15:32:37
 */
public class MesProduceWorkmanshipProcessConverts {

    private static Logger LOG = LoggerFactory.getLogger(MesProduceWorkmanshipProcessConverts.class);

    public static List<MesProduceWorkmanshipProcessDTO> convert(List<MesProduceWorkmanshipProcess> mesProduceWorkmanshipProcessList) {
        if (CollectionUtils.isEmpty(mesProduceWorkmanshipProcessList)) {
            return Collections.EMPTY_LIST;
        }

        List<MesProduceWorkmanshipProcessDTO> mesProduceWorkmanshipProcessListResult = Lists.newArrayList();
        for (MesProduceWorkmanshipProcess mesProduceWorkmanshipProcess : mesProduceWorkmanshipProcessList) {
            mesProduceWorkmanshipProcessListResult.add(convert(mesProduceWorkmanshipProcess));
        }
        return mesProduceWorkmanshipProcessListResult;
    }

    public static MesProduceWorkmanshipProcessDTO convert(MesProduceWorkmanshipProcess mesProduceWorkmanshipProcess) {
        try {
            return BeanUtils.copy(mesProduceWorkmanshipProcess, MesProduceWorkmanshipProcessDTO.class);
        } catch (Exception e) {
            LOG.error("MesProduceWorkmanshipProcess到MesProduceWorkmanshipProcessDTO转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "MesProduceWorkmanshipProcess到MesProduceWorkmanshipProcessDTO转换失败", e);
        }
    }

    public static MesProduceWorkmanshipProcess convert(MesProduceWorkmanshipProcessDTO mesProduceWorkmanshipProcessDTO) {
        try {
            return BeanUtils.copy(mesProduceWorkmanshipProcessDTO, MesProduceWorkmanshipProcess.class);
        } catch (Exception e) {
            LOG.error("MesProduceWorkmanshipProcessDTO到MesProduceWorkmanshipProcess转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "MesProduceWorkmanshipProcessDTO到MesProduceWorkmanshipProcess转换失败", e);
        }
    }
}